#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e5+10;

int ans[N<<1],rt1,rt2,x,n,to1[N],to2[N],cnt = 1,h[N<<1],now[N<<1];
bool vis[N<<3];
struct edge{int v,w,nxt;}e[N<<3];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;e[++cnt] = (edge){x,w,h[y]};h[y] = cnt;}

void dfs(int x){
	for(int i = now[x],y;i;i = e[now[x]].nxt){
		y = e[i].v; now[x] = i; if(vis[i] || vis[i^1]) continue; 
		if(e[i].w) ans[min(x,y)] = x < y ? 1 : -1; vis[i] = vis[i^1] = 1;
		dfs(y); 
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("subtask_1_27.txt","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++){
		x = in;
		if(x == -1) rt1 = i;
		else link(x,i,0),to1[x]++,to1[i]++;
	}
	for(int i = 1;i <= n;i++){
		x = in;
		if(x == -1) rt2 = i;
		else link(x+n,i+n,0),to2[x]++,to2[i]++;
	}
	to1[rt1]++; to2[rt2]++;
	link(n+n+1,rt1,0); link(n+n+1,rt2+n,0);
	for(int i = 1;i <= n;i++)
		if((to1[i] & 1) ^ (to2[i] & 1)) return puts("IMPOSSIBLE"),0;
	puts("POSSIBLE");
	for(int i = 1;i <= n;i++)
		if(to1[i] & 1)
			link(i,i+n,1);
	for(int i = 1;i <= 2 * n + 1;i++) now[i] = h[i];
	dfs(1);
	for(int i = 1;i <= n;i++) printf("%d%c",ans[i]," \n"[i==n]);
	return 0;
}

